package com.example.testdemo.resources;

import org.andengine.opengl.texture.TextureOptions;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.andengine.opengl.texture.atlas.bitmap.BuildableBitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.source.IBitmapTextureAtlasSource;
import org.andengine.opengl.texture.atlas.buildable.builder.BlackPawnTextureAtlasBuilder;
import org.andengine.opengl.texture.atlas.buildable.builder.ITextureAtlasBuilder.TextureAtlasBuilderException;
import org.andengine.opengl.texture.region.ITextureRegion;

import android.util.Log;

import com.example.testdemo.TankGameActivity;

public class MenuInGameResources extends BaseResources {
	private final String TAG = MenuInGameResources.class.getSimpleName();

	private BuildableBitmapTextureAtlas mMenusTextureAtlas;
	public ITextureRegion mMenuResetTextureRegion;
	public ITextureRegion mMenuQuitTextureRegion;

	public MenuInGameResources(TankGameActivity activity) {
		super(activity);
	}
	
	@Override
	public void load(int resources) {
	    BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("menus/");
        mMenusTextureAtlas = new BuildableBitmapTextureAtlas(
                mActivity.getTextureManager(), 512, 512, TextureOptions.BILINEAR);

        mMenuResetTextureRegion = BitmapTextureAtlasTextureRegionFactory
                .createFromAsset(mMenusTextureAtlas, mActivity, "menu_reset.png");
        mMenuQuitTextureRegion = BitmapTextureAtlasTextureRegionFactory
                .createFromAsset(mMenusTextureAtlas, mActivity, "menu_quit.png");

        try {
            mMenusTextureAtlas
                    .build(new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(
                            10, 10, 10));
            mMenusTextureAtlas.load();
        } catch (TextureAtlasBuilderException e) {
            Log.e(TAG, "Create MenuInGameResources failed !", e);
        }
	}

	@Override
	public void unload(int resources) {
		mMenusTextureAtlas.unload();
	}

}
